/*
 * Created on Jan 12, 2009
 */
package ak.salmon;

import java.util.Collections;
import java.util.Map;

public class SalmonLayoutEngineFactory {

    private Map<String, Class< ? extends SalmonLayoutEngine>> map;

    public SalmonLayoutEngineFactory(Map<String, Class< ? extends SalmonLayoutEngine>> config) {
        this.map = Collections.unmodifiableMap(config);
    }

    public SalmonLayoutEngine get(String engine) {
        if (!map.containsKey(engine)) throw new RuntimeException("Engine not defined.");
        try {
            return map.get(engine).newInstance();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
